#!/bin/sh
task_id=$1

if [ $# -lt 1 ]; then
  echo "parameter error, need one parameter, while current have $#..."
  echo "example: ./kill_task.sh 1"
  exit 1
fi

tasks_name="tasks$task_id"
process_id=$(ps -aef | grep amazonAnsiListingSpider.py | grep $tasks_name | grep -v grep | awk '{print $2}')
if [ -z "$process_id" ];then
  echo "not existing service running $tasks_name..."
else
  kill -9 $process_id
  echo "killed existing service: $tasks_name, process_id: $process_id..."
fi

bash ./display_tasks.sh